]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
GtkNotificationDaemon: Add ActionInvoked signal
authorJulian Sparber <julian@sparber.net>
Wed, 17 Apr 2024 10:40:49 +0000 (12:40 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 11 Jul 2024 12:32:33 +0000 (12:32 +0000)
For the notification portal we need to provide the option to use unexported
actions.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3382>

data/dbus-interfaces/org.gtk.Notifications.xml
js/ui/notificationDaemon.js

index 56a6cecbe0fedc83244df2eef3793b778cffdce1..02cd31765f9e1f2733c18281ba31c84074bbb4db 100644 (file)
@@ -9,5 +9,12 @@
       <arg name="app_id" type="s" direction="in"/>
       <arg name="id" type="s" direction="in"/>
     </method>
+    <signal name="ActionInvoked">
+      <arg name="app_id" type="s"/>
+      <arg name="id" type="s"/>
+      <arg name="action" type="s"/>
+      <arg name="parameter" type="av"/>
+      <arg name="platform_data" type="a{sv}"/>
+    </signal>
   </interface>
 </node>
index ff4c26caf6651c02460d16c43209cc250b9cc0f5..16c602f578553218f2e2b45baa33d7ddc2e2c265 100644 (file)
@@ -456,15 +456,11 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
         });
     }
 
-    _activateAction(namespacedActionId, target) {
-        if (namespacedActionId) {
-            if (namespacedActionId.startsWith('app.')) {
-                let actionId = namespacedActionId.slice('app.'.length);
-                this.source.activateAction(actionId, target);
-            }
-        } else {
-            this.source.open();
-        }
+    _activateAction(actionId, target) {
+        if (actionId.startsWith('app.'))
+            this.source.activateAction(actionId.slice('app.'.length), target);
+        else
+            this.source.emitActionInvoked(this.id, actionId, target);
     }
 
     _onButtonClicked(button) {
@@ -473,7 +469,11 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
     }
 
     activate() {
-        this._activateAction(this._defaultAction, this._defaultActionTarget);
+        if (this._defaultAction)
+            this._activateAction(this._defaultAction, this._defaultActionTarget);
+        else
+            this.source.open();
+
         super.activate();
     }
 
@@ -486,7 +486,7 @@ function InvalidAppError() {}
 
 export const GtkNotificationDaemonAppSource = GObject.registerClass(
 class GtkNotificationDaemonAppSource extends MessageTray.Source {
-    constructor(appId) {
+    constructor(appId, dbusImpl) {
         if (!Gio.Application.id_is_valid(appId))
             throw new InvalidAppError();
 
@@ -502,6 +502,7 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
 
         this._appId = appId;
         this._app = app;
+        this._dbusImpl = dbusImpl;
 
         this._notifications = {};
         this._notificationPending = false;
@@ -517,6 +518,22 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
         Main.panel.closeCalendar();
     }
 
+    emitActionInvoked(notificationId, actionId, target) {
+        const context = global.create_app_launch_context(0, -1);
+        const info = this._app.get_app_info();
+        const token = context.get_startup_notify_id(info, []);
+
+        this._dbusImpl.emit_signal('ActionInvoked',
+            GLib.Variant.new('(sssava{sv})', [
+                this._appId,
+                notificationId,
+                actionId,
+                target ? [target] : [],
+                {'activation-token': GLib.Variant.new_string(token)},
+            ])
+        );
+    }
+
     open() {
         this._app.activate();
         Main.overview.hide();
@@ -566,11 +583,11 @@ class GtkNotificationDaemon {
     constructor() {
         this._sources = {};
 
-        this._loadNotifications();
-
         this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GtkNotificationsIface, this);
         this._dbusImpl.export(Gio.DBus.session, '/org/gtk/Notifications');
 
+        this._loadNotifications();
+
         Gio.DBus.session.own_name('org.gtk.Notifications', Gio.BusNameOwnerFlags.REPLACE, null, null);
     }
 
@@ -578,7 +595,7 @@ class GtkNotificationDaemon {
         if (this._sources[appId])
             return this._sources[appId];
 
-        let source = new GtkNotificationDaemonAppSource(appId);
+        const source = new GtkNotificationDaemonAppSource(appId, this._dbusImpl);
 
         source.connect('destroy', () => {
             delete this._sources[appId];